package com.bz.order.controller;

import com.bz.order.service.OrderService;
import com.bz.pojo.TbOrder;
import com.bz.pojo.TbOrderItem;
import com.bz.pojo.TbOrderShipping;
import com.bz.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    /**
     * 创建订单
     * @param orderItem
     * @param tbOrder
     * @param tbOrderShipping
     * @return
     */
    @PostMapping("/insertOrder")
    public Result insertOrder(String orderItem, TbOrder tbOrder , TbOrderShipping tbOrderShipping){
        Result result = Result.formatObjectToList(orderItem, List.class);
        List<TbOrderItem> list = (List<TbOrderItem>)result.getData();
        return orderService.insertOrder(list,tbOrder,tbOrderShipping);
    }
}
